#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
struct ListNode 
{
    int val;
    struct ListNode* next;

};
int maxProfit(int* prices, int pricesSize)
{
    int min = 100000;
    int UnitPrice = 0;
    int SumPrice = 0;
    int i = 0;
    for (i = 0; i < pricesSize; i++)
    {
        if (prices[i] > min)
        {
            UnitPrice = prices[i] - min;
            min = prices[i + 1];
        }
        else
        {
            min = prices[i];
        }
        SumPrice += UnitPrice;
        UnitPrice = 0;
    }
    return SumPrice;
}
int maxProfit2(int* prices, int pricesSize)
{
    int min = 100000;
    int UnitPrice = 0;
    int SumPrice = 0;
    int i = 0;
    for (i = 0; i < pricesSize; i++)
    {
        if (prices[i] > min)
        {
            UnitPrice = prices[i] - min;
            min = prices[i];
            SumPrice += UnitPrice;
        }
        else
        {
            min = prices[i];
        }

    }
    return SumPrice;
}
int main()
{
    int prices[6] = { 7,1,5,3,6,4 };
    int i = maxProfit(prices, 6);
    printf("%d", i);
    return 0;
}
struct ListNode* partition(struct ListNode* head, int x)
{
    struct ListNode* lessHead = NULL, * lessTail = NULL;
    struct ListNode* greaterHead = NULL, * greaterTail = NULL;
    struct ListNode* cur = head;
    if (head == NULL || head->next == NULL)
    {
        return head;
    }
    while (cur)
    {
        if (cur->val < x)
        {
            if (lessHead == NULL)
            {
                lessHead = lessTail = cur;
            }
            else
            {
                lessTail->next = cur;
                lessTail = cur;
            }

        }
        else
        {
            if (greaterHead == NULL)
            {
                greaterHead = greaterTail = cur;
            }
            else
            {
                greaterTail->next = cur;
                greaterTail = cur;
            }

        }
        cur = cur->next;
    }
    if (greaterHead != NULL && lessTail != NULL)
    {
        lessTail->next = greaterHead;
        greaterTail->next = NULL;
        return lessHead;
    }

    else if (lessHead == NULL)
    {
        return greaterHead;
    }
    else
    {
        return lessHead;
    }
}